package com.digital.smartgrow.controller.datacenter;


import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.datacenter.WorkExperiencePageDTO;
import com.digital.smartgrow.entity.datacenter.WorkExperience;
import com.digital.smartgrow.service.datacenter.WorkExperienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 工作经历 前端控制器
 * </p>
 *
 * @author xiewb
 * @since 2022-04-04
 */
@Api(tags = "工作经历")
@RestController
@RequestMapping("${context.prefix}/workExperience")
public class WorkExperienceController {

    @Autowired
    private WorkExperienceService workExperienceService;

    @ApiOperation(value = "列表分页查询")
    @PostMapping("/getListByPage")
    public Object getListByPage(@RequestBody WorkExperiencePageDTO workExperiencePageDTO) {
        return workExperienceService.getListByPage(workExperiencePageDTO);
    }

    @ApiOperation(value = "工作经历详情")
    @GetMapping("/getInfo")
    public Object getInfo(Integer id) {
        if (id == null) return Result.fail("id不能为空");
        return workExperienceService.getInfo(id);
    }

    @ApiOperation(value = "工作经历-删除")
    @GetMapping("/removeById")
    public Object removeById(Integer id) {
        if (id == null) return Result.fail("id不能为空");
        return workExperienceService.removeById(id);
    }

    @ApiOperation(value = "工作经历-新增")
    @PostMapping("/add")
    public Object add(@Valid @RequestBody WorkExperience workExperience) {
        return workExperienceService.save(workExperience);
    }

    @ApiOperation(value = "工作经历-编辑")
    @PostMapping("/edit")
    public Object edit(@Valid @RequestBody WorkExperience workExperience) {
        if (workExperience == null || workExperience.getId() == null) return Result.fail("id不能为空");
        return workExperienceService.updateById(workExperience);
    }
}
